﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.Mmose.Core.Common;

namespace Demo.Mmose.Core.Entity.Suit.Quest
{
    /// <summary>
    /// 
    /// </summary>
    public class QuestObjectiveHandlers
    {
        #region zh-CHS 共有属性 | en Public Properties
        /// <summary>
        /// 
        /// </summary>
        public int Count
        {
            get { return m_QuestObjectiveHandlers.Count; }
        }
        #endregion

        #region zh-CHS 公开方法 | en Public Method

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Dictionary<long, IQuestObjectiveHandler> m_QuestObjectiveHandlers = new Dictionary<long, IQuestObjectiveHandler>();
        #endregion
        /// <summary>
        /// 注册技能光环的处理调用者
        /// </summary>
        /// <param name="iPacketID"></param>
        /// <param name="iLength"></param>
        /// <param name="bInGame"></param>
        /// <param name="onPacketReceive"></param>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的技能光环调用,不支持多线程操作:警告!" )]
        public void Register( long questObjectiveId, IQuestObjectiveHandler questObjectiveHandler )
        {
            if ( questObjectiveHandler == null )
                throw new Exception( "QuestObjectiveHandlers.Register(...) - questObjectiveHandler == null error!" );

            m_QuestObjectiveHandlers.Add( questObjectiveId, questObjectiveHandler );
        }

        /// <summary>
        /// 获取技能光环的处理调用者
        /// </summary>
        /// <param name="iPacketID"></param>
        /// <returns></returns>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的技能光环调用,不支持多线程操作:警告!" )]
        public IQuestObjectiveHandler GetQuestObjectiveHandler( long questObjectiveId )
        {
            IQuestObjectiveHandler questObjectiveHandler = null;
            m_QuestObjectiveHandlers.TryGetValue( questObjectiveId, out questObjectiveHandler );

            return questObjectiveHandler;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="auraId"></param>
        /// <returns></returns>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的技能光环调用,不支持多线程操作:警告!" )]
        public void Apply( long questObjectiveId, QuestObjective questObjective, object arg )
        {
            IQuestObjectiveHandler questObjectiveHandler = null;
            m_QuestObjectiveHandlers.TryGetValue( questObjectiveId, out questObjectiveHandler );

            if ( questObjectiveHandler != null )
                questObjectiveHandler.Apply( questObjective, arg );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="auraId"></param>
        /// <returns></returns>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的技能光环调用,不支持多线程操作:警告!" )]
        public QuestObjective CreateInstance( long questObjectiveId, object arg )
        {
            IQuestObjectiveHandler questObjectiveHandler = null;
            m_QuestObjectiveHandlers.TryGetValue( questObjectiveId, out questObjectiveHandler );

            if ( questObjectiveHandler != null )
                return questObjectiveHandler.CreateQuestObjective( arg );
            else
                return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="auraId"></param>
        /// <returns></returns>
        [MultiThreadedWarning( "zh-CHS", "此处没有锁定用于内部调用的(无锁),请在主世界服务开始的时候注册全部的技能光环调用,不支持多线程操作:警告!" )]
        public QuestObjectiveT CreateInstance<QuestObjectiveT>( long auraId, object arg ) where QuestObjectiveT : QuestObjective
        {
            IQuestObjectiveHandler questObjectiveHandler = null;
            m_QuestObjectiveHandlers.TryGetValue( auraId, out questObjectiveHandler );

            if ( questObjectiveHandler != null )
                return questObjectiveHandler.CreateQuestObjective( arg ) as QuestObjectiveT;
            else
                return null;
        }

        #endregion
    }
}
